package com.zhang.gatewayserver;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.Bean;

/**
 * 测试url:
 *  http://localhost:8768/client/hello?name=qqq
 *  http://localhost:8768/get
 *  http://localhost:8768/EUREKA-CLIENT/hello?name=ldh
 *  http://localhost:8768/RIBBON-SERVER/hello?name=ldh
 *
 * @author zhanghaidong
 */
@EnableEurekaClient
@SpringBootApplication
public class GatewayServerApplication {

    public static void main(String[] args) {
        SpringApplication.run(GatewayServerApplication.class, args);
    }

    @Bean
    public RouteLocator customRouteLocator (RouteLocatorBuilder builder) {
        return builder.routes().
                route("customRoute1", r -> r.path("/get").
                        uri("http://httpbin.org/get")).
                route("RIBBON-SERVER", r -> r.path("/RIBBON-SERVER/**").
                        filters( r1 -> r1.addRequestHeader("Hello","word"))
                        .uri("lb://RIBBON-SERVER")).
                build();
    }

}
